

option explicit


include_once Q_PATH & "\includes\persistence\property.vbs"
include_once Q_PATH & "\includes\persistence\view.vbs"


class CObject

    private m_oIObject
    
    
    public property get oIObject()
        set oIObject = m_oIObject
    end property
    
    public property set oIObject(byval oINewObject)
        set m_oIObject = oINewObject
    end property

    public function sId()
        sId = m_oIObject.GetId
    end function

    public function oSimplePropertyByPosition(byval iPos)
        dim oIProperty
        dim oProperty

        set oIProperty = m_oIObject.GetSimplePropertyByPosition(iPos)
        set oProperty = new CProperty

        set oProperty.oIProperty = oIProperty

        set oSimplePropertyByPosition = oProperty
    end function


    public function oSimpleProperty(byval sPropertyName)
        dim oIProperty
        dim oProperty
        
        set oIProperty = m_oIObject.GetSimpleProperty(sPropertyName)
        set oProperty = new CProperty
        
        set oProperty.oIProperty = oIProperty
        
        set oSimpleProperty = oProperty
    end function


    public function oObjectProperty(byval sPropertyName)
        dim x_oIObject
        dim x_oObject

        set x_oIObject = m_oIObject.GetStoreObjectProperty(sPropertyName)
        set x_oObject = new CObject

        set x_oObject.oIObject = x_oIObject

        set oObjectProperty = x_oObject
    end function


    public function oViewProperty(byval sPropertyName)
        dim x_oIView
        dim x_oView

        set x_oIView = m_oIObject.GetViewProperty(sPropertyName)
        set x_oView = new CView

        set x_oView.oIView = x_oIView

        set oViewProperty = x_oView
    end function


    public function sClassName()
        sClassName = m_oIObject.GetClassName()
    end function

    public function sDescriptor()
        sDescriptor = m_oIObject.GetDescriptor()
    end function


    public function iPropertyCount()
        iPropertyCount = m_oIObject.GetPropertyCount()
    end function
    
    
    public function sPropertyName(byval iIndex)
        sPropertyName = m_oIObject.GetPropertyName(iIndex)
    end function
    

    public function AddDummyProperty(byval oProperty)
        AddDummyProperty = m_oIObject.AddDummyProperty(oProperty.oIProperty.lPointer)
    end function


    public function Refresh()
        Refresh = m_oIObject.Refresh()
    end function


    public function Save()
        Save = m_oIObject.Save()
    end function


    public function Free()
        Free = m_oIObject.Free()
    end function


    public function Delete()
        Delete = m_oIObject.Delete()
    end function

	' criterio para determinar si un objeto es transaccional o no.
	public function bTransactionalObject()
		bTransactionalObject = IsTransactionalClassName(sClassName)
	end function
	
	' informa si tiene una clase tipo list
	private function m_bHasListProperty(byval m_sClassName)
		dim oClass
		dim oProperties
		dim oProperty
		dim bTieneSolapas

		' Optimizacion: Estas consultas se hacen sobre el diccionario. Es performante cuando el diccionario se conecta a una db en el host local.
		' Importante: Los datos obtenidos en este bloque pertenecen a una DB replicada, por lo tanto NO deben modificarse y almacenarse fuera de esta bloque.
	    ' Importante: Se utiliza BeginTrans solo para bloquear el evento OnTimer
'	    oApp.oStorage.BeginTrans
'		    oApp.oStorage.SwitchToDictionaryStorage
		    
			' Obtengo el evento
			set oClass = oApp.oStorage.LoadObject("qclass", "name='"&m_sClassName&"'")
			if oClass is nothing then exit function

			set oProperties = oClass.oViewProperty("propiedades")
			if oProperties is nothing then exit function

			m_bHasListProperty = false
			bTieneSolapas = false
			
			oProperties.open
			if not oProperties.IsEof then oProperties.movefirst

			do while not oProperties.IsEOF() and not bTieneSolapas
				set oProperty = oProperties.oObject

				if oProperty.oSimpleProperty("mode").sValue = Q_PROP_MODE_LIST then 
					bTieneSolapas = true
				end if
				
				if oProperty.oSimpleProperty("mode").sValue = Q_PROP_MODE_INHERIT then 
					bTieneSolapas = m_bHasListProperty(oProperty.oSimpleProperty("class_referenced").sValue)
				end if

				oProperties.movenext
				oApp.oStorage.FreeObject oProperty
			loop
			oProperties.close

			m_bHasListProperty = bTieneSolapas
			
'		    oApp.oStorage.SwitchToDataStorage
		    
	    oApp.oStorage.CommitTrans
	end function
	
	public function bHasListProperty()
		bHasListProperty = m_bHasListProperty(me.sClassName)
	end function
	
end class
